package com.kaifamiao.demo.d0728;


// 有子必须先有父
public class Sup {

    int a = 1;
    static int b = 2;

    {
        System.out.println("Sup: {}");
    }

    static {
        System.out.println("Sup: static{}");
    }

    public Sup(){
        System.out.println("Sup()");
    }

    public Sup(int a){
        System.out.println("Sup(int a)");
    }

    public void instanceMethod(){
        System.out.println("sup::instanceMethod");
    }

    public void test(String a){
        System.out.println(a);
    }

    public static void staticMethod(){
        System.out.println("Sup:staticMethod");
    }
}

class Sub extends Sup{

    static int a = 3;
    int b = 4;

    {
        System.out.println("Sub: {}");
    }

    static{
        System.out.println("Sub: static{}");
    }

    // super 关键字在子类中使用, 表示 父类对象。 super 调用父类的成员  super([参数列表]) 调用父类构造
    public Sub(){
//        super(1);
//        super(); // 先调用父类，进行父类实例化. 必须在构造的第一行
        System.out.println("Sub()");
    }

    public void show(){
        System.out.println("a = " + a); // 3  this.a
        System.out.println("this.a = " + this.a); // 3 this.a
        System.out.println("super.a = " + super.a); // 1 super.a
        System.out.println("b = " + b); // 4 this.b
        System.out.println("this.b = " + this.b); // 4
        System.out.println("super.b = " + super.b);// 2
    }

    @Override
    public void instanceMethod(){
        System.out.println("sub :: instanceMethod");
    }

    public static void staticMethod(){
        System.out.println("Sub:staticMethod");
    }


    public static void main(String[] args) {
        Sub sub = new Sub();
        sub.test("abc");
    }

}
